package com.le.tester.book.effectivejava3rdchinese.articletweenserven;

import org.omg.CORBA.PRIVATE_MEMBER;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * createTime：2022/8/17 14:46
 * description：
 */
public class Demo {

    private static final int SIZE = 10;

    private String[] strings = new String[]{};

    //非法的使用SuppressWarnings注解
    public <T> T[] toArray(T[] a) {
        if (a.length < SIZE) {

            @SuppressWarnings("unchenked") T[] result = (T[]) Arrays.copyOf(strings, SIZE, a.getClass());
            return result;

        }
        System.arraycopy(strings, 0, a, 0, SIZE);
        if (a.length > SIZE) {
            a[SIZE] = null;
            return a;
        }
        return null;
    }
}
